package jespeak;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import jespeak.translation.Translator;
import joptsimple.OptionParser;
import joptsimple.OptionSet;

public class JeSpeak {

	public static void main(String[] args) {
		try {
			//Configure the logger
			Logger logger = Logger.getLogger("jespeak");
			logger.setLevel(Level.WARNING);
//			logger.setLevel(Level.INFO);

			OptionParser parser = new OptionParser("l:");
			OptionSet options = parser.parse(args);
			String lang = "en";
			if (options.has("l")) {
				System.out.println(options.valuesOf("l").size());
				lang = (String) options.valueOf("l");
			}

			String initial = "Hello";
			if (!options.nonOptionArguments().isEmpty()) {
				initial = (String) options.nonOptionArguments().get(0);
			}

			String rulesPath = "dict-source" + File.separator + lang + "_rules";
			String listPath = "dict-source" + File.separator + lang + "_list";


			Translator translator = new Translator(lang, rulesPath, listPath);
			initial = "We have a mutual acquaintance 4";
//			initial = "I am";
			String s = translator.textToPhoneme(initial);
			System.out.println(initial);
			System.out.println(s);

		} catch (FileNotFoundException ex) {
			System.err.println("File not found: en_rules: " + ex.getMessage());
		} catch (IOException ex) {
			System.err.println("File i/o problem: en_rules");
		} catch (Exception ex) {
			System.err.println("Error in translator: " + ex.getMessage());

		}


	}
}
